package com.bye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bye.dto.ProductCategoryDto;
import com.bye.mapper.ProductCategoryMapper;
import com.bye.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {

    @Autowired
    private ProductCategoryMapper productCategoryMapper;
    @Override
    public IPage<ProductCategoryDto> showProductCategory(ProductCategoryDto productCategoryDto) {
        Page<ProductCategoryDto> page = new Page<>(productCategoryDto.getCurrentPage(), productCategoryDto.getPageSize());
        QueryWrapper<ProductCategoryDto> qr  = new QueryWrapper();
        qr.orderByAsc("category_sort");
        return  productCategoryMapper.selectPage(page,qr);
    }

    @Override
    public int deleteProductCategory(ProductCategoryDto productCategoryDto) {
        return  productCategoryMapper.deleteById(productCategoryDto.getId());

    }

    @Override
    public int changeEnabled(ProductCategoryDto productCategoryDto) {
        QueryWrapper<ProductCategoryDto> qr = new QueryWrapper();
        qr.eq("id", productCategoryDto.getId());
        return productCategoryMapper.update(productCategoryDto, qr);
    }

    @Override
    public ProductCategoryDto selectCategory(ProductCategoryDto productCategoryDto) {
        return productCategoryMapper.selectById(productCategoryDto.getId());
    }

    @Override
    public int changeCategory(ProductCategoryDto productCategoryDto) {
        QueryWrapper<ProductCategoryDto> qr = new QueryWrapper();
        qr.eq("id",productCategoryDto.getId());
        return productCategoryMapper.update(productCategoryDto, qr);
    }
}
